﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Test1.MyClasses;

namespace Test1.MyClassesTest
{
    [TestClass]
    public class FileProcessDataDriven : TestBase
    {
        //private const string CONNECT_STRING = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=tests;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

        [TestMethod]
        public void FileExistsTestFromDB()
        {
            FileProcess fp = new FileProcess();
            bool fromCall = false;
            bool testFailed = false;
            string fileName;
            bool expectedValue;
            bool causeException;
            string sql = "SELECT * FROM FileProcessTest";
            //string CONN = CONNECT_STRING;
            string CONN = TestContext.Properties["ConnectionString"].ToString();

            LoadDataTable(sql, CONN);

            if(TestDataTable!=null)
            {
                foreach(DataRow row in TestDataTable.Rows)
                {
                    fileName = row["FileName"].ToString();
                    expectedValue = Convert.ToBoolean(row["ExpectedValue"]);
                    causeException = Convert.ToBoolean(row["CausesException"]);

                    try
                    {
                        fromCall = fp.FileExists(fileName);
                    }
                    catch (ArgumentNullException)
                    {

                        if(!causeException)
                        {
                            testFailed = true;
                        }
                    }

                    TestContext.WriteLine($"Testing FIle: Expected Value:{fileName}," );
                }

                if(testFailed)
                {
                    Assert.Fail("data driven tests have failed");
                }
            }
        }
    }
}
